package triDemo;

import java.awt.*;
import javax.swing.*;

public class RunWindow {

	JButton startButton;
	JButton closeButton;
	JButton clearFileButton;
	JButton clearLogButton;
	JButton runButton;
	
	JTextField fileText;
	JLabel stateLabel;
	
	public RunWindow(Instance l) {
		init();
		startButton.addActionListener(l);
		closeButton.addActionListener(l);
		runButton.addActionListener(l);
		clearFileButton.addActionListener(l);
		clearLogButton.addActionListener(l);
		l.setDisplay(this);
	}
	
	public void display(String str) {
		stateLabel.setText(str);
	}
	
	public String getFileName() {
		return fileText.getText();
	}
	
	private void init() {
		JFrame f = new JFrame("Tri Project");
		JPanel opPanel = this.createOpPanel();
		JPanel triPanel = this.createTriPanel();
		stateLabel = new JLabel("Tri State...........................");		
		
		
		JPanel mainp = new JPanel();
		GridBagConstraints c = new GridBagConstraints();
		GridBagLayout gmgr = new GridBagLayout();
		
		mainp.setLayout(gmgr);

		c.weightx = 1;
		
		c.fill = GridBagConstraints.CENTER;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.gridheight = 1;
		c.weighty = 0.8;
		mainp.add(triPanel, c);
		
		
		c.fill = GridBagConstraints.CENTER;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.gridheight = 1;
		c.weighty = 0.8;
		mainp.add(opPanel, c);
		
		
		c.fill = GridBagConstraints.CENTER;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.gridheight = 1;
		c.weighty = 1;
		mainp.add(stateLabel, c);
		
		
		f.add(mainp);
		//f.pack();
		f.setBounds(0, 0, 500, 200);
		f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		f.setVisible(true);
	}
	
	private JPanel createTriPanel() {
		JPanel panel = new JPanel();
		GridBagConstraints c = new GridBagConstraints();
		GridBagLayout gmgr = new GridBagLayout();
		
		panel.setLayout(gmgr);
		
		startButton = new JButton("Start Tri");
		closeButton = new JButton("Close Tri");
		clearFileButton = new JButton("Clear File");
		clearLogButton = new JButton("Clear Log");
		
		c.weightx = 1;
		c.gridwidth = 1;
		c.gridheight = 1;
		c.weighty = 0.5;
		c.fill = GridBagConstraints.CENTER;
		
		panel.add(startButton, c);
		panel.add(closeButton, c);
		panel.add(clearFileButton, c);
		panel.add(clearLogButton, c);
		
		
		return panel;
	}
	
	private JPanel createOpPanel() {
		JPanel panel = new JPanel();
		
		JLabel label = new JLabel("FileName = ");
		fileText = new JTextField("instruction.txt", 20);
		runButton = new JButton("Run");
		
		GridBagConstraints c = new GridBagConstraints();
		GridBagLayout gmgr = new GridBagLayout();
		panel.setLayout(gmgr);
		
		c.fill = GridBagConstraints.VERTICAL;
		c.gridwidth = 2;
		c.gridheight = 1;
		panel.add(label, c);
		
		c.fill = GridBagConstraints.BOTH;
		c.gridwidth = 7;
		panel.add(fileText, c);
		
		c.fill = GridBagConstraints.VERTICAL;
		c.gridwidth = 1;
		panel.add(runButton, c);
		
		//panel.setSize(100, 30);
		
		return panel;
	}
	
	
}
